/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-08-02
 * Time: 23:25
 */
class Fruit extends Food{

}

class Food {

}
class Apple extends Fruit {

}

class Banana extends Fruit {

}

class Message<T> { // 设置泛型
    private T message ;
    public T getMessage() {
        return message;
    }
    public void setMessage(T message) {
        this.message = message;
    }
}

public class Test1 {

    public static void func1(Message<? super Fruit> message) {
        message.setMessage(new Banana());
        message.setMessage(new Apple());
        Fruit banana = (Fruit) message.getMessage();//发生向下转型
    }

    public static void func(Message<? extends Fruit> message) {
        //这样接收也体现了泛型的上届
        Fruit banana = message.getMessage();//发生向上转型
    }

    public static void main(String[] args) {
        Message<Banana> message1 = new Message<>();

        Message<Apple> message2 = new Message<>();
        func(message1);
        func(message2);
       /*//不满足泛型的上届
        Message<Food> message3 = new Message<>();
        func(message3);*/

    }
}
